{include file="public/_head" /}
<!-- /Navbar -->
<!-- Main Container -->
<div class="main-container container-fluid">
    <!-- Page Container -->
    <div class="page-container">

        <!-- Page Sidebar -->
        {include file="public/_left" /}
        <!-- /Page Sidebar -->
        <!-- Page Content -->
        <div class="page-content">
            <!-- Page Breadcrumb -->
            <div class="page-breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="fa fa-home"></i>&nbsp;文章管理
                    </li>
                    <li>文章列表</li>
                </ul>
            </div>
            <!-- /Page Breadcrumb -->
            <!-- Page Body -->
            <div class="page-body">
                <a href="{:url('admin/article/add')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;添加文章</a>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="widget">
                            <div class="widget-header">
                                <span class="widget-caption">文章列表</span>
                                <div class="widget-buttons">
                                    {$articles->render()|raw|replace}
                                </div>
                            </div>
                            <div class="widget-body">
                                <table class="table table-hover table-bordered">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>文章标题</th>
                                        <th>所属导航</th>
                                        <th>推荐</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    {volist name="articles" id="vol"}
                                    <tr>
                                        <td>{$vol.id}</td>
                                        <td>{$vol.title}</td>
                                        <td>{$vol.cate.catename}</td>
                                        <td>{if $vol.is_top == 1}已推荐{else /}未推荐{/if}</td>
                                        <td>
                                            {if $vol.is_top == 1}
                                            <a href="#" class="btn btn-sm btn-darkorange article-top" istop="{$vol.is_top}" dataid="{$vol.id}">取消推荐</a>
                                            {else /}
                                            <a href="#" class="btn btn-sm btn-info article-top" istop="{$vol.is_top}" dataid="{$vol.id}">推荐</a>
                                            {/if}
                                            <a href="{:url('admin/article/edit',['id' => $vol.id])}" class="btn btn-sm btn-warning">编辑</a>
                                            <a href="#" class="btn btn-sm btn-danger articel-del" dataid="{$vol.id}">删除</a>
                                        </td>
                                    </tr>
                                    {/volist}
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->

    </div>
    <!-- /Page Container -->
    <!-- Main Container -->

</div>

{include file="public/_js" /}
<script>
    $(function () {
         //分页；给pagination添加样式
        $('.pagination').addClass('pagination-sm');

        $('.article-top').click(function () {
            var id = $(this).attr('dataid');
            var is_top = $(this).attr('istop');
            if (is_top == 1){
                var msg = '确定取消推荐？';
            }else {
                var msg = '确定推荐？';
            }
            layer.confirm(msg,{
                title:'推荐操作',
                icon:3,
            },function (index) {
                layer.close(index);
                $.ajax({
                   url:"{:url('admin/article/top')}",
                   type:'post',
                   data:{id:id,is_top:is_top},
                   dataType:'json',
                   success:function (data) {
                       if (data.code == 1){
                           layer.msg(data.msg,{
                              icon:6,
                              time:1200
                           },function () {
                               location.href = data.url;
                           });
                       }else {
                           layer.open({
                              title:'操作失败',
                              contain:data.msg,
                              icon:5,
                              anim:6
                           });
                       }
                   }
                });
            });
            return false;
        });

        //文章删除
        $('.articel-del').click(function () {
            var id = $(this).attr('dataid');
            //询问块
            layer.confirm('确定删除？',{
                title:'删除文章',
                icon:3
            },function (index) {
                //关闭询问块
                layer.close(index);
                $.ajax({
                   url:"{:url('admin/article/del')}",
                   type:'post',
                   data:{id:id},
                   dataType:'json',
                   success:function (data) {
                       if (data.code == 1){
                          layer.msg(data.msg,{
                             icon:6,
                             time:1200
                          },function () {
                              location.href = data.url;
                          });
                       } else {
                           layer.open({
                              title:'删除失败',
                              content:data.msg,
                              icon:5,
                              anim:6
                           });
                       }
                   }
                });
            });
            return false;
        });
    });


</script>
</body>
<!--  /Body -->
</html>
